/*
 * Copyright (C) 2010-2011 sunjumper@163.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package mf.mfrpc.serialize;

import java.io.InputStream;

/**
 * 流数据适配类。
 */
public class AdapterDataSource implements DataSource {

    protected String name;

    protected transient InputStream inputStream;

    protected long size = -1;

    protected long lastModified = 0;

    protected String digest;

    public AdapterDataSource() {
    }

    public AdapterDataSource(DataSource dataSource) {
        this.inputStream = dataSource.getInputStream();
        this.name = dataSource.getName();
        this.size = dataSource.getSize();
        this.lastModified = dataSource.getLastModified();
    }

    public AdapterDataSource(String name, InputStream inputStream, long size, long lastModified) {
        this.name = name;
        this.inputStream = inputStream;
        this.size = size;
        this.lastModified = lastModified;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    @Override
    public InputStream getInputStream() {
        return inputStream;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return name;
    }

    public void setSize(long size) {
        this.size = size;
    }

    @Override
    public long getSize() {
        return size;
    }

    public void setLastModified(long lastModified) {
        this.lastModified = lastModified;
    }

    @Override
    public long getLastModified() {
        return lastModified;
    }

    /**
     * 设置流数据的消息摘要。
     * 
     * @param digest 流数据的消息摘要。
     */
    public void setDigest(String digest) {
        this.digest = digest;
    }

    @Override
    public String getDigest() {
        return digest;
    }
}
